﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace MvcApplication.Dal
{
    public class StudentDal
    {
        public static DataTable GetStudent(string sqlText)
        {
            string con = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            using (SqlConnection connect = new SqlConnection(con))
            {
                try
                {
                    connect.Open();
                    using (SqlCommand cmd = new SqlCommand(sqlText, connect))
                    {
                        DataTable dt = new DataTable();
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        dt = new DataTable();
                        adapter.Fill(dt);
                        return dt;
                    }
                }
                catch (SqlException e)
                {
                    connect.Close();
                    throw e;
                }
            }
        }
    }
}